package com.spagettikod.t437.action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;

import com.spagettikod.t437.T437;
import com.spagettikod.t437.component.domain.DomainJList;
import com.xerox.amazonws.sdb.SDBException;
import com.xerox.amazonws.sdb.SimpleDB;

public class DeleteDomainAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4605959456153734527L;

	private DomainJList domainJList;

	public DeleteDomainAction(DomainJList domainJList) {
		this.domainJList = domainJList;
		putValue(Action.NAME, "Delete");
	}

	public void actionPerformed(ActionEvent arg0) {
		int result = JOptionPane
				.showConfirmDialog(
						T437.getApplicationFrame(),
						"Are you REALLY sure you want to delete this domain? ALL DATA WILL BE LOST!",
						"Delete Domain", JOptionPane.YES_NO_OPTION);
		if (result == JOptionPane.YES_OPTION) {
			SimpleDB sdb = T437.getConfigurator().getSimpleDB();
			try {
				T437.setBusyCursor(true);
				sdb.deleteDomain(domainJList.getSelectedDomain().getName());
				domainJList.refresh();
			} catch (SDBException e) {
				T437.displayErrorMessage("Error Deleting Domain", e
						.getLocalizedMessage());
			} finally {
				T437.setBusyCursor(false);
			}
		}
	}

}
